package kevin.study.zephyr.domain.model.base;

import kevin.study.zephyr.util.UUIDUtil;

import java.io.Serializable;
import java.util.Date;


/**
 * 基类
 *
 * @author Kevin.Huang
 * @createtime 2007-9-20
 */
public class Base implements Serializable {

    /**
     * 主键的名称
     */
    public static final String FILTER_PK_ID = "uuid";

    /**
     *
     */
    private static final long serialVersionUID = 3508708709361643419L;

    /**
     * 各个对象的UUID
     */
    private String uuid;

    private Date createTime;

    private Date modifyTime;

    /**
     * 对各自对象的描述
     */
    private String description;

    /**
     * 默认构造函数
     */
    public Base() {
        uuid = UUIDUtil.generateUUID();
        createTime = new Date();
        modifyTime = new Date();
    }

    /**
     * 清除属性
     */
    public void clear() {
        uuid = null;
        createTime = null;
        modifyTime = null;
    }

    /**
     * @return the uuid
     */
    public String getUuid() {
        return uuid;
    }

    /**
     * @param uuid the uuid to set
     */
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /*
      * (non-Javadoc)
      *
      * @see java.lang.Object#hashCode()
      */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((uuid == null) ? super.hashCode() : uuid.hashCode());
        return result;
    }

    /*
      * (non-Javadoc)
      *
      * @see java.lang.Object#equals(java.lang.Object)
      */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Base)) {
            return false;
        }
        final Base other = (Base) obj;
        if (uuid == null) {
            return other.uuid == null && super.equals(obj);
        } else if (!uuid.equals(other.uuid)) {
            return false;
        }
        return true;
    }

    /**
     * 判断对象是否已被初始化
     *
     * @return true 对象已被初始化 false 对象没被初始化
     */
    public boolean isInited() {
        return uuid != null;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return the modifyTime
     */
    public Date getModifyTime() {
        return modifyTime;
    }

    /**
     * @param modifyTime the modifyTime to set
     */
    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }
}
